﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.Library;
using System.Data;
using IHISCETeim.BLL;

namespace IHISCETeim.Web.AgentSys.PWMgr
{
    public partial class AgentPartOrderList : EasyUIPageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看, Permission.修改, Permission.新增, Permission.删除 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "AgentPartOrderList";
            }
        }


        #region 属性 (查询条件)
        /// <summary>
        /// 排序字段 值为 id
        /// </summary>
        protected override string orderField
        {
            get
            {
                return string.IsNullOrEmpty(base.orderField) ? "OrderId" : base.orderField;
            }
        }
        /// <summary>
        ///  排序方式 desc或 asc
        /// </summary>
        protected override string orderDirection
        {
            get
            {
                return string.IsNullOrEmpty(base.orderDirection) ? "DESC" : base.orderDirection;
            }
        }


        protected override string SQLSort
        {
            get
            {
                return (orderField + " " + orderDirection);
            }
        }
       
        [QueryColumnName(), QueryOperator(QueryOperatorsEnum.包含)]
        public string AgentName
        {
            get
            {
                return GetRequestValue<string>("AgentName", "");

            }
        }
        [QueryColumnName(), QueryOperator(QueryOperatorsEnum.包含)]
        public string OrderNumber
        {
            get
            {
                return GetRequestValue<string>("OrderNumber", "");

            }
        }
        [QueryColumnName(), QueryOperator(QueryOperatorsEnum.包含)]
        public string SerialNumber
        {
            get
            {
                return GetRequestValue<string>("SerialNumber", "");

            }
        }
        [QueryColumnName(), QueryOperator(QueryOperatorsEnum.包含)]
        public string CustomerName
        {
            get
            {
                return GetRequestValue<string>("CustomerName", "");

            }
        }
        public string IssueDateForm
        {
            get
            {
                return GetRequestValue<string>("IssueDateForm", "");

            }
        }

        public string IssueDateTo
        {
            get
            {
                if (string.IsNullOrEmpty(IssueDateForm))
                {
                    return "";
                }
                else
                {
                    string todate = GetRequestValue<string>("IssueDateTo", "");
                    if (string.IsNullOrEmpty(todate))
                        return Convert.ToDateTime(IssueDateForm).AddDays(1).ToShortDateString();
                    else
                        return todate;
                }

                // return GetRequestValue<string>("IssueDateTo", "");

            }
        }

        protected string GetSql()
        {
            string sqlwhere = QueryFiledHelper.GetSqlWhere(this);

            if (!string.IsNullOrEmpty(IssueDateForm))
            {
                string DOWNSQL = QueryOperatorsEnumHelper.ConvertCommonOperator("IssueDate", QueryOperatorsEnum.范围, IssueDateForm + "|" + IssueDateTo);
                if (!string.IsNullOrEmpty(sqlwhere))
                {
                    sqlwhere += " and " + DOWNSQL;
                }
                else
                {
                    sqlwhere = DOWNSQL;
                }
            }
            string _agentname = base.User.IsSuperAdmin?"": HasPower(Permission.经销商平台_经销商) ? base.User.UserId.ToString() : "";
            if (!string.IsNullOrEmpty(_agentname))
            {
                string sqlcommonFiled = string.Format("AgentId in ({0})", _agentname);
                if (!string.IsNullOrEmpty(sqlwhere))
                {
                    sqlwhere += " and " + sqlcommonFiled;
                }
                else
                {
                    sqlwhere = sqlcommonFiled;
                }
            }

            return sqlwhere;
        }

        protected override string query()
        {
            DataTable dts = AgentPartOrderController.GetPagination(GetSql(), pageNum, numPerPage, SQLSort, ref TotalCount);

            return ToDataGridJson(dts, TotalCount, null).ToString();
        }


        #endregion
    }
}